package cn.tedu.eb_film.ex.handler;

import cn.tedu.eb_film.ex.ServiceException;
import cn.tedu.eb_film.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 *
 * @author daiojie
 * @since 2023/03/18 12:56:48
 *
 */

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler
    public JsonResult<Void> handleServiceException(ServiceException e){
        log.warn("程序运行过程中出现ServiceException,将统一处理");
        log.warn("异常信息:{}",e.getMessage());
        return JsonResult.fail(e.getCode(),e.getMessage());
    }
}
